package com.bw.eurekaribbon.web;

import com.bw.common.dto.UserDTO;
import com.bw.common.vo.ResultVO;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
public class ErpController {

    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/get/erp/list")
    @HystrixCommand(fallbackMethod = "getErpListHystrix")
    public ResultVO getErpList(){
        // 获取erp 的信息

        //获取用户的信息
        UserDTO userDTO = new UserDTO();
        userDTO.setPageNO(1);
        userDTO.setPageSize(50);
        HttpEntity httpEntity = new HttpEntity(userDTO);
        ResultVO body = restTemplate.postForEntity("http://EUREKA-CLIENT-1/user/list/page", httpEntity,ResultVO.class).getBody();
        Object obj = body.getObject();
        //处理业务逻辑
        return ResultVO.success();
    }

    public ResultVO  getErpListHystrix(){
        log.info("/get/erp/list 出现异常...");
        return ResultVO.fail("500","服务器异常...",null);
    }
}
